const gulp = require('gulp')
const JSON5=require('json5')
const fs = require('fs')
const node_xj = require("xls-to-json")
const xlsx = require('node-xlsx');


gulp.task('default', function() {

  node_xj({
    input: "input.xlsx",  // input xls
    output: "./newData.json5", // output json
  }, function(err, result) {
    if(err) {
      console.error(err)
    } else {
      console.log(result)

      jsonObj = JSON5.stringify(result, null, 2)
      fs.writeFile("./newData.json5",jsonObj,'utf-8', function(err) {
        if(err) {
          return console.log(err);
        }
      })
    }
  })

  const channel = xlsx.parse("input.xlsx");
  const channelData = channel[0]
  const channelDataStr = channelData.data
  console.log(">>> " , channelDataStr)

  console.log("Hello Gulp!")
  return new Promise((resolve) => {
    resolve()
  })
})

gulp.task('lint', function() {
  return gulp.src([
    '*./source/ts/**/**.ts', './test/**/**.test.ts'
  ]).pipe(tslint())
    .pipe(tslint.report('verbose'))
})
